package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.Order;
import com.health.service.OrderService;
import com.health.utils.Constant;
import com.health.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 查询预约详情
     */
    @GetMapping("/findDetail/{id}")
    public Result findDetail(@PathVariable Integer id) {
        Map<String, Object> detail = orderService.findDetail(id);
        return new Result(true, "查询预约详情成功", detail);
    }

    /**
     * 提交预约
     */
    @PostMapping("/add")
    public Result add(@RequestBody Order order) {
        //预约方式
        order.setOrderType(Constant.ORDER_TYPE_SELF);
        //到诊状态
        order.setOrderStatus(Constant.ORDER_STATUS_NO);
        //添加预约信息，获取预约id
        int orderId = orderService.add(order);
        return new Result(true, "预约成功", orderId);
    }

    /**
     * 判断是否重复预约
     */
    @PostMapping("/checkOrder")
    public Result checkOrder(@RequestBody Order order) {
        int count = orderService.findCountByCondition(order);
        if (count > 0) {
            return new Result(false, "已预约过，不能重复预约");
        }
        return new Result(true, "预约信息正常");
    }
}
